package com.chaodev.base.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.InteractionQrcodeDao;
import com.chaodev.base.dto.InteractionQrcodeDto;
import com.chaodev.base.model.InteractionQrcode;
import com.chaodev.base.service.InteractionQrcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InteractionQrcodeServiceImpl implements InteractionQrcodeService {

    @Autowired
    private InteractionQrcodeDao interactionQrcodeDao;

    @Override
    public boolean addInteractionQrcode(InteractionQrcode interactionQrcode) {
        
        return interactionQrcodeDao.insertInteractionQrcode(interactionQrcode) != 0;
    }

    @Override
    public boolean editInteractionQrcode(InteractionQrcode interactionQrcode) {
        return interactionQrcodeDao.updateInteractionQrcode(interactionQrcode) != 0;
    }

    @Override
    public boolean saveInteractionQrcode(InteractionQrcode interactionQrcode) {
        if (ObjectUtil.isNotNull(interactionQrcode.getId()) && !"".equals(interactionQrcode.getId())){
            interactionQrcode.setUpdateUser(interactionQrcode.getCreateUser());
            return editInteractionQrcode(interactionQrcode);
        }
        return addInteractionQrcode(interactionQrcode);
    }

    @Override
    public boolean removeInteractionQrcode(InteractionQrcode interactionQrcode) {
        return interactionQrcodeDao.deleteInteractionQrcode(interactionQrcode.getId()) != 0;
    }

    @Override
    public List<InteractionQrcode> getInteractionQrcodeList(InteractionQrcodeDto interactionQrcodeDto) {
        return interactionQrcodeDao.selectInteractionQrcodeList(interactionQrcodeDto);
    }

    @Override
    public InteractionQrcode getInteractionQrcodeById(InteractionQrcode interactionQrcode) {
        return interactionQrcodeDao.selectInteractionQrcodeById(interactionQrcode.getId());
    }

    @Override
    public PageInfo<InteractionQrcode> getInteractionQrcodePage(InteractionQrcodeDto interactionQrcodeDto) {
        PageHelper.startPage(interactionQrcodeDto.getPage(),interactionQrcodeDto.getRows());
        List<InteractionQrcode> list = interactionQrcodeDao.selectInteractionQrcodeList(interactionQrcodeDto);
        PageInfo<InteractionQrcode> pageInfo = new PageInfo<>(list, interactionQrcodeDto.getRows());
        return pageInfo;
    }
    
}
